#!/usr/bin/env Rscript

# Test script for pcfcross3D functionality

require(spatstat.explore)

# Create a simple 3D multitype point pattern for testing
set.seed(42)

# Create some random points in a unit cube
n_points <- 100
coords <- matrix(runif(n_points * 3), ncol=3)

# Create marks (two types)
marks <- factor(sample(c("A", "B"), n_points, replace=TRUE, prob=c(0.6, 0.4)))

# Create pp3 object (assuming spatstat.geom is available)
# Note: This requires spatstat.geom to be installed
if(require(spatstat.geom)) {
  
  # Create box domain
  box <- spatstat.geom::box3(xrange=c(0,1), yrange=c(0,1), zrange=c(0,1))
  
  # Create pp3 object with marks
  X <- spatstat.geom::pp3(x=coords[,1], y=coords[,2], z=coords[,3], domain=box, marks=marks)
  
  cat("Created 3D multitype point pattern with", npoints(X), "points\n")
  cat("Mark frequencies:\n")
  print(table(marks(X)))
  
  # Test is.multitype function
  cat("\nTesting is.multitype:\n")
  print(is.multitype(X))
  
  # Test that pattern is multitype
  cat("\nPattern is multitype:\n")
  print(is.multitype(X))
  
  # Test pcfcross3D function
  cat("\nTesting pcfcross3D function:\n")
  try({
    g_cross <- pcfcross3D(X, "A", "B", rmax=0.5, nrval=50)
    cat("pcfcross3D completed successfully\n")
    print(summary(g_cross))
  })
  
  # Test with same type
  cat("\nTesting pcfcross3D with same type (A-A):\n")
  try({
    g_same <- pcfcross3D(X, "A", "A", rmax=0.5, nrval=50)
    cat("pcfcross3D A-A completed successfully\n")
    print(summary(g_same))
  })
  
} else {
  cat("spatstat.geom not available - skipping tests\n")
}